package com.web.music.portal.mvc;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.web.music.model.ChangePasswordForm;

public class ChangePasswordFormValidator implements Validator {

	public boolean supports(Class givenClass) {
		return ChangePasswordForm.class.equals(givenClass);
	}

	public void validate(Object obj, Errors errors) {
		com.web.music.model.ChangePasswordForm form = (ChangePasswordForm) obj;
		if (form == null) {
			errors.reject("error.nullpointer", "Null data received");
		} else {
			if (! form.getPassword().equals(form.getRepeatpassw())) {
				errors.rejectValue("password", "password.notmatch", "Passwords should match!");
				errors.rejectValue("repeatpassw", "password.notmatch", "Passwords should match!");
			}
		}
	}

}
